package cn.com.spic.demo.controller;

import cn.com.spic.demo.api.OrganizationService;
import cn.com.spic.demo.dto.OrgaizationDTO;
import cn.com.spic.demo.dto.SecGroupMessageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/org")
public class OrganizationController {
    @Autowired
    private OrganizationService organizationService;

    @GetMapping("/getOrgs")
    public List<OrgaizationDTO> getOrgs(HttpServletRequest request){
        String orgId = request.getParameter("orgId");
        String[] allOrgId = orgId.split(",");
        List<OrgaizationDTO> dtos = organizationService.getOrgaizations(allOrgId);
        return dtos;
    }
    @GetMapping("/getAllOrgs")
    public List<OrgaizationDTO> getAllOrgs(HttpServletRequest request){
        String pageIndex = request.getParameter("pageIndex");
        String pageSize = request.getParameter("pageSize");
        Map<String,Integer > map = new HashMap<>();

        map.put("beginNumber",Integer.parseInt(pageIndex)*Integer.parseInt(pageSize));
        map.put("endNumber",Integer.parseInt(pageSize));

        List<OrgaizationDTO> dtos = organizationService.getAllOrgs(map);
        return  dtos;
    }

    /**
     * 二级单位名称+code
     * @return
     */
    @GetMapping("/getSecGroupInFourAction")
    public List<SecGroupMessageDTO> getSecGroupInFourAction() {
        return organizationService.getSecGroupInFourAction();
    }

    /**
     * 集团部门名称+code
     * @return
     */
    @GetMapping("/getSecGroupInThreeAction")
    public List<SecGroupMessageDTO> getSecGroupInThreeAction() {
        return organizationService.getSecGroupInThreeAction();
    }
}
